﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PocketMahjong.Core
{
	public static class TileSet
	{
		private static List<Tile> _list;
		public static IEnumerable<Tile> GetAllTiles()
		{
			if (_list == null)
			{
				_list = new List<Tile>();
				for (int n = 1; n <= 4; n++)
					for (int i = 1; i <= 9; i++)
						_list.Add(new Tile(TileKind.Dot, i));
				for (int n = 1; n <= 4; n++)
					for (int i = 1; i <= 9; i++)
						_list.Add(new Tile(TileKind.Bamboo, i));
				for (int n = 1; n <= 4; n++)
					for (int i = 1; i <= 9; i++)
						_list.Add(new Tile(TileKind.Character, i));
				for (int n = 1; n <= 4; n++)
					for (int i = 1; i <= 4; i++)
						_list.Add(new Tile(TileKind.Wind, i));
				for (int n = 1; n <= 4; n++)
					for (int i = 1; i <= 3; i++)
						_list.Add(new Tile(TileKind.Dragon, i));
				for (int i = 1; i <= 4; i++)
					_list.Add(new Tile(TileKind.Season, i));
				for (int i = 1; i <= 4; i++)
					_list.Add(new Tile(TileKind.Flower, i));

				System.Diagnostics.Debug.Assert(_list.Count == 144);
			}
			return _list;
		}

		public static bool Match(this Tile a, Tile b)
		{
			if (a.Kind == b.Kind)
			{
				if (a.Kind == TileKind.Season || a.Kind == TileKind.Flower)
					return true;
				else
					return a.Number == b.Number;
			}
			else
				return false;
		}
	}
}
